package com.icesoft.generation.stater;

import com.icesoft.generation.entity.GenDtoField;
import com.icesoft.generation.entity.GenField;
import com.icesoft.generation.entity.GenTable;
import com.icesoft.generation.entity.GenVoField;
import com.icesoft.generation.helper.TableJavaFileHelper;
import com.icesoft.generation.service.impl.GenFieldDtoServiceImpl;
import com.icesoft.generation.service.impl.GenFieldServiceImpl;
import com.icesoft.generation.service.impl.GenFieldVoServiceImpl;
import com.icesoft.generation.service.impl.GenTableServiceImpl;
import com.icesoft.generation.vo.GenTableVO;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import java.util.List;

@Slf4j
@Component
@Order
@RequiredArgsConstructor
public class GenAutoInitializer implements ApplicationRunner {

	private final GenTableServiceImpl genTableService;

	private final GenFieldServiceImpl genFieldService;

	private final GenFieldVoServiceImpl genFieldVoService;

	private final GenFieldDtoServiceImpl genFieldDtoService;

	@Override
	public void run(ApplicationArguments args) throws Exception {
//		List<GenTableVO> tables = TableJavaFileHelper.getTables();

//		for (GenTableVO table : tables) {
//			GenTable genTable = genTableService.lambdaQuery()
//					.eq(GenTable::getPackageName, table.getPackageName())
//					.eq(GenTable::getTableName, table.getTableName())
//					.eq(GenTable::getTableComment, table.getTableComment())
//					.eq(GenTable::getModuleName, table.getModuleName())
//					.eq(GenTable::getClassName, table.getClassName())
//					.one();
//			if (genTable != null) {
//				continue;
//			}
//			genTableService.save(table);
//			if (table.getFields() != null) {
//				for (GenField field : table.getFields()) {
//					field.setTableId(table.getId());
//					genFieldService.save(field);
//				}
//			}
//			if (table.getVoFields() != null) {
//				for (GenVoField field : table.getVoFields()) {
//					field.setTableId(table.getId());
//					genFieldVoService.save(field);
//				}
//			}
//			if (table.getDtoFields() != null) {
//				for (GenDtoField field : table.getDtoFields()) {
//					field.setTableId(table.getId());
//					genFieldDtoService.save(field);
//				}
//			}
//		}
	}
}
